// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';


// 申明请求对象
const calTeamRequest = {
    // calTeam请求的基本url
    BASE_URL : confing.CAL_URL + "/calTeam",

    //行编辑按钮的弹窗 根据id编辑班组信息
    edit(calTeam,callback){
        if(calTeam != undefined && calTeam.teamId != undefined){
            request.put(this.BASE_URL + "/update",calTeam,callback)
        }
    },
    //行编辑按钮 需要根据id查询角色信息的api
    get(teamId,callback){
        // 如果有teamId就准备url
        if(teamId){
            // 准备url
            let url = this.BASE_URL + "/get?teamId=" + teamId;
            request.get(url,callback);//调用get方法
        }
        // 如果没有roleId,就不做任何处理
    },

    //批量删除班组
    deletes(teamIds,callback){
        // 拼接URL
        let url = this.BASE_URL + "/deletes?t=1";
        if(teamIds != undefined){
            teamIds.forEach(teamId => {
                url += "&teamId=" + teamId;
            });
            request.delete( url,callback);
        }
    },


    //删除选中班组
    delete(teamId,callback){
        request.delete(this.BASE_URL + "/" + teamId,callback);
    },

    // 添加班组
    save(calTeam,callback){
        if(calTeam){
            request.post(this.BASE_URL + "/save",calTeam,callback);
        }
    },

    // 生成生产工单编号
    autoTeamCode(callback) {
        request.get("http://localhost:8280/gen", callback);
    },

    // 班组列表展示 分页
    list(page = 1,limit = 10,calTeam,callbcak){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(calTeam){
            if(calTeam.teamCode){
                url += "&teamCode=" + calTeam.teamCode;
            }
            if(calTeam.teamName){
                url += "&teamName=" + calTeam.teamName;
            }
            if(calTeam.calendarType){
                url += "&calendarType=" + calTeam.calendarType;
            }
        }
        // 发送请求
        request.get(url,callbcak);
    }

}


// 将calTeamRequest暴漏出去
export default calTeamRequest;
